package com.ts.proj.controller;

import com.alibaba.fastjson.JSONArray;
import com.ts.base.controller.BaseController;
import com.ts.common.constant.ConsoleConstant;
import com.ts.proj.service.SystemColumnService;
import com.ts.proj.service.SystemFieldService;
import com.ts.util.FieldListUtil;
import com.ts.util.JurisdictionUtil;
import com.ts.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class SystemFieldController extends BaseController {

    @Autowired
    private SystemColumnService systemColumnService;

    @Autowired
    private SystemFieldService systemFieldService;

    /**
     * 字段描述
     * @return
     */
    @RequestMapping("/field-list")
    public ModelAndView fieldList(){
        ModelAndView modelAndView = this.getModelAndView();
        String viewName = "login";
        if(JurisdictionUtil.isValid()){

            Object attribute = this.getRequest().getSession().getAttribute(ConsoleConstant.BTNRIGHTS);
            List<PageData> buttonList = (List<PageData>) JSONArray.parse(attribute.toString());
            modelAndView.addObject("buttons", buttonList);
            //先从Redis里面读取-----------------SystemFieldEntity--------attributes freezAttributes-------------------
            PageData pageData = FieldListUtil.fieldsList(systemColumnService, "SystemFieldEntity", systemFieldService);
            List<PageData> attributes = (List<PageData>) pageData.get("all");
            List<PageData> freezAttributes = (List<PageData>) pageData.get("freeze");
            if(freezAttributes.size()!=0){
                modelAndView.addObject("freeze", pageData.get("freeze"));
            }
            //------------------------dadfafadfadfaf--------------------
            //应该在这里添加列头
            modelAndView.addObject("attributes", pageData.get("all"));
            viewName = "system/field-list";
        }
        modelAndView.setViewName(viewName);
        return modelAndView;
    }


}
